
axios.defaults.baseURL='http://localhost:8081'

//1 使用axios前置拦截器，让所有的请求都携带uToken
axios.interceptors.request.use(config=>{
    //携带token
    let token =  localStorage.getItem("token");
    if(token){
        config.headers['token']=token;
    }
    return config;
},error => {
    Promise.reject(error);
})
//2 使用axios后置拦截器，处理没有登录请求
axios.interceptors.response.use(result=>{
    debugger;
    console.log(result.data+"jjjjjjj");
    let data = result.data;  // {success:false,message:"noLogin"}
    // 说明后端返回错误信息是 未登录，那么就要跳转到登录页面
    if(!data.success && data.message==="noLogin"){
        alert("请登陆后再操作")
        location.href="/index.html";
    }
    return result;
},error => {
    Promise.reject(error);
})

Vue.prototype.$http=axios;
function  str2Obj(url){
    let paramStr=url.split("?")[1];
    if (paramStr){
        let paramArray=paramStr.split("&");
        let paramObj={};
        $.each(paramArray,function (index,param){
            //console.log(param);
            let paramName=param.split("=")[0];
            let paramValue=param.split("=")[1];
            paramObj[paramName]=paramValue;
        })
        return paramObj;
    }
}
let excludePath=["/index.html","/callback.html","/binder.html","/exam.html"];
let isRun=false;
let url=location.href;
for (let i=0;i<excludePath.length;i++){
    let path=excludePath[i];
    if (url.indexOf(path)>-1){
        isRun=true;
        break;
    }
}
if (url==="http://127.0.0.1:80" || url==="http://wx.rongcarservice.com/"){
    isRun=true;
}
if (!isRun){
    let loginInfo=localStorage.getItem("loginInfo");
    if (!loginInfo){
        alert("请登录");
        location.href="/exam.html";
    }
}